Column

Chart A: Scatterplot

Column

Chart B: Boxplot

Chart C: Boxplot

---
title: "hw4_flexdashboard"
author: "Yuechu Hu"
date: "2024-10-28"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
library(plotly)
library(flexdashboard)
library(tidyverse)
library(dplyr)
```


```{r, include=FALSE}
ny_noaa = read_csv("./data/nynoaadat.csv")
```


```{r, include=FALSE}
ny_noaa_clean = ny_noaa %>%
  janitor::clean_names() %>%
  mutate(
    year = year(date),
    tmax = tmax / 10,    
    tmin = tmin / 10, 
    prcp = prcp / 10
  ) 
```





Column {data-width=650}
-----------------------------------------------------------------------

### Chart A: Scatterplot

```{r, echo = FALSE}
ny_noaa_clean %>%
  filter(year == 2000) %>%
  plot_ly(
    x = ~tmax,
    y = ~prcp,
    type = "scatter", 
    mode = "markers",
    alpha = 0.5
  ) %>%
  layout(title = "Scatterplot of Precipitation vs Max Temperature",
         xaxis = list(title = "Maximum Temperature (C)"),
         yaxis = list(title = "Precipitation (mm)"))
```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B: Boxplot

```{r, echo = FALSE}
ny_noaa_clean %>%
  group_by(year) %>%
  summarize(avg_snow = mean(snow, na.rm = TRUE)) %>%
  plot_ly(x = ~year, 
          y = ~avg_snow, 
          type = 'bar') %>%
  layout(title = "Average Snowfall by Year",
         xaxis = list(title = "Year"),
         yaxis = list(title = "Average Snowfall (mm)"))
```

### Chart C: Boxplot

```{r, echo = FALSE}
ny_noaa_clean %>%
  plot_ly(x = ~factor(year), 
          y = ~tmax, 
          type = 'box') %>%
  layout(title = "Boxplot of Max Temperature by Year",
         xaxis = list(title = "Year"),
         yaxis = list(title = "Maximum Temperature (C)"))
```